<template>
  <div id="login_id">
    <div class="login_back">
      <div class="top">
        <img src="../assets/logo.926d2fa6.png" alt="" />
        <p><span>优质甄选</span>·<span>高枕无忧</span></p>
      </div>
      <form action="">
        <input
          type="text"
          name="username"
          id="username"
          placeholder="请输入您的用户名"
          v-model="shuju.username"
        />
        <br />
        <input
          type="password"
          name="password"
          id="password"
          placeholder="请输入相应的密码"
          v-model="shuju.password"
        />
        <br />
        <input type="button" value="登录" class="button" @click="login" />
      </form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      shuju: {
        username: "admin",
        password: "admin888",
      },
    };
  },
  methods: {
    login() {
      // 判断当前值是否为空
      if (this.shuju.username == "" || this.shuju.password == "") {
        return alert("请输入用户名或密码");
      }
      this.$http.post("/api/userlogin", this.shuju).then((res) => {
        if (res.code == 200) {
          // 当登录存放本地数据
          let token = JSON.stringify(res.list);
          localStorage.setItem("loginture", token);
          alert("登录成功");
          return this.$router.push("/layout");
        } else {
          return alert("用户名不存在");
        }
      });
    },
  },
};
</script>

<style>
#login_id {
  width: 100%;
  height: 100vh;
  background-image: linear-gradient(#fc684e, #e97070);
  position: relative;
}
#login_id .login_back {
  width: 900px;
  height: 600px;
  background-image: url("../assets/loginbg.a14bd0f6.png");
  background-size: 100% 100%;
  position: absolute;
  top: 65px;
  right: 150px;
}
#login_id .login_back .top img {
  width: 382px;
  position: absolute;
  right: 77px;
  top: 123px;
}
#login_id .login_back .top p {
  position: absolute;
  right: 134px;
  top: 260px;
  font-size: 20px;
  color: #c2bfbe;
  letter-spacing: 10px;
}
#login_id .login_back form {
  width: 382px;
  position: absolute;
  top: 361px;
  right: 68px;
  padding: 5px 10px;
}
#username,
#password {
  width: 100%;
  border: none;
  outline: none;
  height: 40px;
  background-color: #fff2ef;
  border-bottom: 1px solid #ffa18f;
  margin-bottom: 20px;
}
#login_id .login_back form .button {
  width: 100%;
  height: 40px;
  border-radius: 20px;
  text-align: center;
  color: white;
  background-color: #f95239;
  outline: none;
  border: none;
  padding-left: 38px;
  box-sizing: border-box;
  letter-spacing: 38px;
}
</style>